package com.wy.controller;

import com.wy.model.Result;
import com.wy.model.Room;
import com.wy.service.RoomService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2019/12/510:39
 */
@Api("restful风格的api示例")
@RestController
@RequestMapping("room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @ApiOperation(value = "查询列表")
    @GetMapping("list")
    public Result<Room> list1(HttpServletRequest request, Room room,
                              @RequestParam(defaultValue = "1") int pagenum,
                              @RequestParam(defaultValue = "2") int pagesize){
        Page<Room> page = roomService.pagelist(room,pagenum,pagesize);
        return new Result(page.getTotalElements(),page.getContent());
    }

    @ApiOperation(value = "普通查询列表")
    @GetMapping("listmh")
    public List<Room> list2(HttpServletRequest request, Room room){
        return roomService.list(room);
    }

    @ApiOperation(value = "查询单条")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "用户id",required = true,paramType = "path")})
    @ApiResponses({@ApiResponse(code=400,message="id为空")})
    @GetMapping("getById/{id}")
    public Room getById(@PathVariable String id){
        return roomService.getById(id);
    }
    @ApiOperation(value = "新增修改")
    @PostMapping("save")
    public Room save(@RequestBody Room room){
        return roomService.save(room);
    }
    @ApiOperation(value = "删除")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "用户id",required = true,paramType = "path")})
    @ApiResponses({@ApiResponse(code=400,message="id为空")})
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable String id){
        roomService.delete(id);
        return true;
    }
}
